import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Dashboard.vue'),
    meta: {
      title: '智能报表平台'
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: () => import('@/views/Profile.vue'),
    meta: {
      title: '我的'
    }
  },
  {
    path: '/dashboard',
    redirect: '/'
  },
  {
    path: '/charts',
    name: 'Charts',
    component: () => import('@/views/Charts.vue'),
    meta: {
      title: '图表展示'
    }
  },
  {
    path: '/data-table',
    name: 'DataTable',
    component: () => import('@/views/DataTable.vue'),
    meta: {
      title: '数据表格'
    }
  },
  {
    path: '/analytics',
    name: 'Analytics',
    component: () => import('@/views/Analytics.vue'),
    meta: {
      title: '数据分析'
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta?.title) {
    document.title = to.meta.title as string
  }
  next()
})

export default router